﻿using Org.BouncyCastle.Utilities.Encoders;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PasswdTool.SM4
{
    public class CryptData
    {
        public CryptData() { }
        public CryptData(byte [] data)
        {
            this.Data = data;
        }
        public byte[] Data { get; internal set; }

        public string ToHexStr()
        {
            return Hex.ToHexString(this.Data);
        }
        public string ToBase64Str()
        {
            return Encoding.UTF8.GetString(Base64.Encode(this.Data));
        }

        public override string ToString()
        {
            return Encoding.UTF8.GetString(this.Data);
        }
        public CryptData FromHexStr(string data)
        {
            CryptData cryptData = new CryptData
            {
                Data = Hex.Decode(data)
            };
            return cryptData;
        }
        public CryptData FromBase64Str(string data)
        {
            CryptData cryptData = new CryptData
            {
                Data = Base64.Decode(data)
            };
            return cryptData;
        }
    }
}
